package meng.study.thread.queue.block;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class MyWorker implements Delayed {

	private int id;
	private String name;
	private long delayTime;
	private String workContext;
	
	

	public MyWorker(int id, String name, long delayTime, String workContext) {
		super();
		this.id = id;
		this.name = name;
		this.delayTime = delayTime;
		this.workContext = workContext;
	}

	public MyWorker() {
		super();
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getDelayTime() {
		return delayTime;
	}

	public void setDelayTime(long delayTime) {
		this.delayTime = delayTime;
	}

	public String getWorkContext() {
		return workContext;
	}

	public void setWorkContext(String workContext) {
		this.workContext = workContext;
	}

	@Override
	public int compareTo(Delayed delayed) {
		TimeUnit unit = TimeUnit.SECONDS;
		return (int) (this.getDelay(unit) - delayed.getDelay(unit));
	}

	@Override
	public long getDelay(TimeUnit unit) {
		return unit.toMillis(this.delayTime) + System.currentTimeMillis();
	}

}
